<?php
$program = "java -jar /home/dieend/Project/mushroom-clasfication-weka/WekaMushroomApplication/dist/WekaMushroomApplication.jar ";
$result=array();
if ($_FILES["file"]["size"]>=0 && isset($_POST["model_name"])) {
    if (isset($_POST["extension"])) {
        $extension = $_POST["extension"];
    } else {
        $extension = end(explode('.', $_FILES["file"]["name"]));
    }
    if (move_uploaded_file($_FILES["file"]["tmp_name"], "data/".$_POST["model_name"].".".$extension)) {
        if ($extension == "csv") exec($program . "convert data/".$_POST["model_name"].".".$extension);
        chmod ("data/".$_POST["model_name"].".".$extension ,  0777 );
        $result["status"] = "ok";
        $result["link"] = "http://".$_SERVER["HTTP_HOST"]."/wekaws/data/{$_POST['model_name']}";
        $result["name"] = $_POST['model_name'];
        echo json_encode($result);
    } else {
        $result["status"] = "fail";
        echo json_encode($result);
    }
}
?>
